<template>
  <div>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '编辑',
                icon: 'ant-design:edit-outlined',
                onClick: handleEdit.bind(null, record),
                // auth: 'other', // 根据权限控制是否显示: 无权限，不显示
              },
              {
                label: '删除',
                icon: 'ic:outline-delete-outline',
                onClick: handleDelete.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup>
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { getArticleColumns, searchFormSchema } from '../tableData';

  import { getAritcleListApi } from '@/api/hopefly/api';
  import { useGo } from '@/hooks/web/usePage';

  const go = useGo();
  const [registerTable] = useTable({
    title: '',
    // api: getAritcleListApi,
    api: (params) => {
      return getAritcleListApi(params);
    },
    columns: getArticleColumns(),
    pagination: { pageSize: 10 },
    showIndexColumn: false,
    bordered: true,
    useSearchForm: true,
    actionColumn: {
      width: 160,
      title: '操作',
      dataIndex: 'action',
    },
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
    },
  });
  function handleEdit(record: any) {
    go('/article/edit/' + record.id, true);
  }
  function handleDelete(record: any) {
    console.log('handleEdit', record);
  }
</script>
